package com.hotel.service;

import com.hotel.entity.Checkin;
import com.hotel.repository.CheckinRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service("checkinService")
public class CheckinService {
    private final CheckinRepository repository;

    public CheckinService() {
        this.repository = new CheckinRepository();
    }

    public void save(Checkin checkin) {
        repository.save(checkin);
    }

    public List<Map<String, Object>> findByParam(Map<String, Object> map) {
        String guest_name;
        String room_number;
        String id_card;
        String status;
        String startDate;
        String endDate;
        if (map.get("guest_name") == null) {guest_name = "";}
        else guest_name = map.get("guest_name").toString();

        if (map.get("room_number") == null) {room_number = "";}
        else room_number = map.get("room_number").toString();

        if (map.get("id_card") == null) {id_card = "";}
        else id_card = map.get("id_card").toString();

        if (map.get("status") == null) {status = "";}
        else status = map.get("status").toString();

        if(map.get("startDate")==null) {startDate = "";}
        else startDate = map.get("startDate").toString();

        if(map.get("endDate")==null) {endDate = "";}
        else endDate = map.get("endDate").toString();

        return repository.findByParam(guest_name, id_card, room_number, status, startDate, endDate);
    }

    public List<Map<String, Object>> findAll() {
        return repository.findAll();
    }

    public void checkout(int id, String check_out_time) {
        repository.checkout(id, check_out_time);
    }

    public void update(int id,Checkin checkin) {
        checkin.setCheckin_id(id);
        repository.update(checkin);
    }
    public List<Map<String, Object>> getActive() {
        return repository.getActive();
    }

    public Optional<Map<String, Object>> findById(int guest_id) {
        return repository.findById(guest_id);
    }

    public List<Map<String, Object>> findCheckinsByIdCard(String id_card) {
        return repository.findCheckinsByIdCard(id_card);
    }
}
